package com.project.service.impl;

import com.project.bean.FacilitiesBean;
import com.project.mapper.IFacilitiesMapper;
import com.project.service.IFacilitiesService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class FacilitiesServiceImpl extends BaseService implements IFacilitiesService {
    @Override
    public List<FacilitiesBean> findRoomFacilities(int id) {
        SqlSession session = this.getSession();
        IFacilitiesMapper mapper = session.getMapper(IFacilitiesMapper.class);
        List<FacilitiesBean> list = mapper.findRoomFacilities(id);
        session.close();
        return list;
    }

    @Override
    public void addFacilities(FacilitiesBean facilitiesBean, Integer roomId) {
        SqlSession session = this.getSession();
        IFacilitiesMapper mapper = session.getMapper(IFacilitiesMapper.class);
        mapper.addFacilities(facilitiesBean,roomId);
        session.commit();
        session.close();
    }

    @Override
    public void changeFacilities(Integer facilitiesId, String status) {
        SqlSession session = this.getSession();
        IFacilitiesMapper mapper = session.getMapper(IFacilitiesMapper.class);
        mapper.changeFacilities(facilitiesId,status);
        session.commit();
        session.close();
    }

    @Override
    public int countRoom(int roomId, String status) {
        SqlSession session = this.getSession();
        IFacilitiesMapper mapper = session.getMapper(IFacilitiesMapper.class);
        int num = mapper.countRoom(roomId,status);
        session.close();
        return num;
    }

    @Override
    public void deFacilities(int roomId) {
        SqlSession session = this.getSession();
        IFacilitiesMapper mapper = session.getMapper(IFacilitiesMapper.class);
        mapper.deFacilities(roomId);
        session.commit();
        session.close();
    }
}
